<?php 
//include 'Crypto.class.php';

function hexToBinary(&$hexData) {
	return pack('H*', $hexData);
}

function current_millis() {
	list($usec, $sec) = explode(" ", microtime());
	return round(((float)$usec + (float)$sec) * 1000);
}

function pkcs5_pad ($text, $blocksize) 
{ 
    $pad = $blocksize - (strlen($text) % $blocksize); 
    return $text . str_repeat(chr($pad), $pad); 
} 

$myKey = '용인';
$myIV  = '초기값';
$myMsg = pkcs5_pad('qwer12345', 16);


//$myKey = hexToBinary($myKey);
//$myIV = hexToBinary($myIV);

$myKey = md5($myKey, true);
$myIV = md5($myIV, true);

//$aes = new Crypto(AES_MODE_CBC, AES_PAD_NULLS_SAFE, 128);
//$aes->setHexKey($myKey);
//$aes->setHexIV($myIV);

$enc_module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($enc_module, $myKey, $myIV);

$dec_module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($dec_module, $myKey, $myIV);

//$cipherText = mcrypt_generic($enc_module, $data);
//$decrypted = mdecrypt_generic($dec_module, $data);



$loop = 1;
$start = current_millis();
echo $myMsg;
echo '<br />';
for($i = 0; $i< $loop; $i++ ){
	$cipherText = base64_encode( mcrypt_generic($enc_module, $myMsg) );
	$decrypted = mdecrypt_generic( $dec_module, base64_decode($cipherText) );
	if( $i == $loop -1 ){
		echo $cipherText;
		echo '<br />';
		echo $decrypted;
		echo '<br />';
	}
}
$end = current_millis();
echo ($end - $start)/ 1000;

mcrypt_generic_deinit($enc_module);
mcrypt_generic_deinit($dec_module);
mcrypt_module_close($enc_module);
mcrypt_module_close($dec_module);
?>